package com.application.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import com.application.component.GetUrl;
/** ============================================================================= **/
public class MethodPost {
	public StringBuffer buff			= new StringBuffer();
	GetUrl post							= new GetUrl();
	
	public String doPost(String url,String param) throws IOException{
		
		HttpURLConnection connection;
		OutputStreamWriter request		= null;
		URL getUrl						= null;
        String temp						= null;
        String response 				= null;  
		
		String urlComplete				= post.urlPostMethod+url;
		getUrl							= new URL(urlComplete);
		try {
			connection						= (HttpURLConnection) getUrl.openConnection();
			connection.setDoOutput(true);
			connection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0");
			connection.setRequestProperty("Accept_Language", "en-US");
			connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			connection.setRequestMethod("POST");
			
			request 					= new OutputStreamWriter(connection.getOutputStream());
            request.write(urlComplete);
            request.flush();
            request.close();
            
            String line 				= "";               
            InputStreamReader isr 		= new InputStreamReader(connection.getInputStream());
            BufferedReader reader 		= new BufferedReader(isr);
            StringBuilder sb 			= new StringBuilder();
            
            while ((line = reader.readLine()) != null)
            {

                sb.append(line + "\n");
            }
            
            temp						= sb.toString();               
            response 					= sb.toString();
            isr.close();
            reader.close();
		} catch (IOException e) {
			// TODO: handle exception
		}
		return param;		
	}
}
/** ============================================================================= **/
